package com.example.demo.thread.volatiles;

/**
 * 测试volatile 的可见性
 *
 * @author luowj12
 * @since 2021/6/24 9:12
 */
public class RunThread extends Thread {

    volatile private boolean isRunning = true;

    public boolean isRunning() {
        return isRunning;
    }

    public void setRunning(boolean isRunning) {
        this.isRunning = isRunning;
    }

    @Override
    public void run() {
        System.out.println("进入到run方法中了");
        while (isRunning == true) {
            System.out.println("循环中。。。。。");
            try {
                Thread.sleep(500);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        System.out.println("线程执行完成了");
    }
}
